﻿namespace FFF.Test.Application.Framework
{
    using System;
    using System.Collections.Generic;
    using System.Reflection;
    using System.Text;
    using Abp.AutoMapper;
    using Abp.Modules;
    using Abp.Reflection.Extensions;
    using Abp.Threading.BackgroundWorkers;
    using FFF.Test.Application.Framework;
    using FFF.Test.Application.Framework.Providers;
    using FFF.Test.DataAccess.Framework;
    using FFF.Test.Entity;
    using FFF.Test.Util.Consts;
    using FFF.Test.Workers;

    /// <summary>
    /// 应用层模块
    /// </summary>
    [DependsOn(
        typeof(YudmAbpApplication01FWModule),
        typeof(YudmAbpApplication02WXModule),
        typeof(YudmAbpApplication04CFDemoModule),
        typeof(YudmAbpApplication99DemoModule),
         typeof(YudmAbpApplication99FrameWorkModule)
        )]
    public class YudmAbpApplicationModule : AbpModule
    {
        /// <summary>
        /// 初始化应用层配置
        /// </summary>
        public override void PreInitialize()
        {
        }

        /// <summary>
        /// 依赖注入初始化
        /// </summary>
        public override void Initialize()
        {
            Assembly thisAssembly = typeof(YudmAbpApplicationModule).GetAssembly();

            this.IocManager.RegisterAssemblyByConvention(thisAssembly);

            this.Configuration.Modules.AbpAutoMapper().Configurators.Add(
               cfg => cfg.AddProfiles(thisAssembly)
           );

            // 在这配置 automapper中的一些特殊映射规则
            this.Configuration.Modules.AbpAutoMapper().Configurators.Add(
              cfg =>
              {
                  // cfg.AddProfiles(thisAssembly);
                  // cfg.CreateMap<TestA, TestC>().ForMember(u => u.Name2,
                  //  options => options.MapFrom(input => input.Name))
                  // .ForMember(u => u.Password, options => options.Ignore())
                  // .ForMember(u => u.Email, options => options.MapFrom(input => input.EmailAddress));
              }
            );

        }

        /// <summary>
        /// woker初始化
        /// </summary>
        public override void PostInitialize()
        {
            IBackgroundWorkerManager workManager = base.IocManager.Resolve<IBackgroundWorkerManager>();
            workManager.Add(base.IocManager.Resolve<MyWorker>());
        }
    }
}
